/** @file TestApplication.qml
    @brief Test application program for the Framework objects.

    To use another test change the declarative view startup document in
    main.cpp

    @authorname \n
    @licenseversion \n
    @actualversion - @dateupdate

    @licensenote
*/
import QtQuick 1.0
import "./" as Framework

Item {
    id: screen

    // Set the screen sizes if the application should run on the Desktop
    // uncommenting the following line. See the MapLoader object
//    width: 360; height: 640

    function toolbarButton1() {
        infopage.state = "Hide";
        homepage.state = "Show";
        mappage.state = "Hide";
    }
    function toolbarButton2() {
        infopage.state = "Hide";
        homepage.state = "Hide";
        mappage.state = "Show";
    }
    function toolbarButton3() {
        infopage.state = "Show";
        homepage.state = "Hide";
        mappage.state = "Hide";
    }

    // Map View
    Item {
        id: mappage
        width: parent.width; height: parent.height
        state: "Hide"

        // Map view object with navigaton controls
        // Comment the MapLoader to run the application on the Desktop
        // See on top of the object
//        Framework.MapLoader {
//            id: viewmap
//            width: mappage.width; height: mappage.height - 115;
//            anchors.top: mappage.top; anchors.topMargin: 115
//            theme: "default"; obj: "MapView"
//        }
        states: [
            State { name: "Show"; AnchorChanges { target: mappage; anchors.left: screen.left } },
            State { name: "Hide"; AnchorChanges { target: mappage; anchors.left: screen.right } }
        ]
        transitions: Transition {
            AnchorAnimation { duration: 500; easing.amplitude: 1; easing.type: Easing.OutQuad }
        }
    }

    // Home page
    Item {
        id: homepage

        width: screen.width; height: screen.height * 0.75
        anchors.left: parent.left; anchors.top: parent.top
        anchors.topMargin: 115; state: "Hide"
        // Background
        Rectangle {
            id: homebackground
            width: parent.width; height: parent.height
            color: "#ffffff"; radius: 15
            border.width: 3; border.color: "#666666"
        }
        // Example loading a theme image with local methods
        BorderImage {
            id: homeimage
            source: "themes/default/SplashObject.png"
            width: parent.width
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
        }

        Framework.Loader {
            id: btnQuit

            width: 160; height: 45
            anchors.horizontalCenter: homeimage.horizontalCenter
            anchors.top: homeimage.bottom
            anchors.topMargin: 10
            theme: "default"; obj: "Button"; obj_string: "Press to Exit"
            onClicked: { Qt.quit() }
        }

        states: [
            State { name: "Show"; AnchorChanges { target: homepage; anchors.left: screen.left } },
            State { name: "Hide"; AnchorChanges { target: homepage; anchors.left: screen.right } }
        ]

        transitions: Transition {
            AnchorAnimation { duration: 500; easing.amplitude: 1; easing.type: Easing.OutQuad }
        }
    }

    // Infobox associated to the toolbar button
    Item {
        id: infopage

        width: parent.width; height: parent.height * 0.75
        anchors.left: parent.left; anchors.top: parent.top
        anchors.topMargin: 115; state: "Hide"
        // Background
        Rectangle {
            id: formbackground
            width: parent.width; height: parent.height
            color: "#ffffff"; radius: 15
            border.width: 3; border.color: "#666666"
        }
        // Title
        Text {
            id: textTitle
            anchors.top: formbackground.top; anchors.topMargin: 20
            anchors.horizontalCenter: formbackground.horizontalCenter
            wrapMode: TextEdit.NoWrap; text: "Qt-Complex 1.0 Beta"
            font.weight: Font.Bold; font.pointSize: 10
        }
        // Text
        Text {
            id: textIntro
            width: formbackground.width
            anchors.top: textTitle.bottom
            anchors.topMargin: 25; anchors.leftMargin: 35; anchors.rightMargin: 35
            wrapMode: TextEdit.Wrap; font.weight: Font.Normal; font.pointSize: 8
            text: "Test application showing some of the features" +
                  " of the Qt-Complex UI framework.<br><br>" +
                  "Version: 1.0.0 beta<br>" +
                  "Author: enrico.miglino@ovi.com<br>" +
                  "Project site: http://projects.forum.nokia.com/Qt_Complex"
        }
        states: [
            State { name: "Show"; AnchorChanges { target: infopage; anchors.left: screen.left } },
            State { name: "Hide"; AnchorChanges { target: infopage; anchors.left: screen.right } }
        ]

        transitions: Transition {
            AnchorAnimation { duration: 500; easing.amplitude: 1; easing.type: Easing.OutQuad }
        }
    }

    // Loads the toolbar
    Framework.Loader {
        id: toolbarLoader
        anchors.top: screen.top; anchors.topMargin: 60; width: screen.width
        theme: "default"; obj: "ToolBar"
        onBtn1click: toolbarButton1();
        onBtn2click: toolbarButton2();
        onBtn3click: toolbarButton3();
    }

    // Top banner shown over all the pages of the aplication. The remaining objects
    // shouldbe shown under this.
    Framework.Loader {
        id: topbannerLoader;
        width: screen.width; anchors.top: screen.top
        theme: "default";
        obj: "StaticBanner"
    }

    // Load a message box. When the user click on it, the splash screen
    // actually hidden, is destroyed. Then also the message box.
    Framework.Loader {
        id: messageAppStarted
        width: parent.width * .80 //formbackground.width
        height: parent.height * 0.40 //ormbackground.height
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        theme: "default"; obj: "MessageBox";
        obj_message: "The application is loaded. Pess the button to destroy the SplashScreen"
        obj_string: "Press Here"
        onClicked: { splashScreen.customSplash = ""; messageAppStarted.destroyAfter = true; }
    }

    // Load a custom splash screen using the ShowSplas method
    Framework.ShowSplash {
        id: splashScreen
        width: parent.width
        height: parent.height
        customSplash: "themes/default/Splash.qml"
        slpashAnimDuration: 2000
        waitDuration: 3000
        }
}
